<template>
  <div class="top-category">
    <div class="container">
      <!-- 面包屑 -->
      <div class="bread-container">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>
            <a href="/">{{ categoryData.name }}</a>
          </el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <!-- 轮播图 -->
      <div class="home-banner">
        <el-carousel height="500px">
          <el-carousel-item v-for="item in bannerList" :key="item.id">
            <img :src="item.imgUrl" />
          </el-carousel-item>
        </el-carousel>
      </div>
      <!--  分类数据模块 -->
      <div class="sub-list">
        <h3>全部分类</h3>
        <ul>
          <li v-for="item in categoryData.children" :key="item.id">
            <router-link :to="`/category/sub/${item.id}`">
              <img :src="item.picture" />
              <p>{{ item.name }}</p>
            </router-link>
          </li>
        </ul>
      </div>
      <div
        class="ref-goods"
        v-for="item in categoryData.children"
        :key="item.id"
      >
        <div class="head">
          <h3>{{ item.name }}</h3>
        </div>
        <div class="body">
          <GoodsItem
            v-for="good in item.goods"
            :key="good.id"
            :good="good"
          ></GoodsItem>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineOptions } from "vue";
//引入自定义封装的hooks
import { useCategory } from "./composables/useCategory";
import { useBanner } from "./composables/useBanner";
//引入公用组件插槽模式
import GoodsItem from "../Home/components/GoodsItem.vue";
defineOptions({
  name: "Category",
});
//解构数据
const { categoryData } = useCategory();
const { bannerList } = useBanner();
</script>

<style scoped lang="scss">
.bread-container {
  padding: 25px 0;
  color: #666;
}
.sub-list {
  margin: 20px 0;
  background-color: #fff;
  text-align: center;
  h3 {
    padding: 20px 0;
    font-size: 30px;
    font-weight: normal;
  }
  ul {
    display: flex;
    justify-content: space-between;
    padding: 20px 0;
    li {
      padding: 20px 30px;
      img {
        width: 100px;
        height: 100px;
      }
      p {
        margin-top: 10px;
      }
      &:hover {
        transform: translate3d(0, -3px, 0);
        box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
      }
    }
  }
}
.ref-goods {
  margin: 20px 0;
  background-color: #fff;
  .head {
    text-align: center;
    h3 {
      font-size: 30px;
      font-weight: normal;
      padding: 15px 0;
    }
  }
  .body {
    display: flex;
    justify-content: space-between;
    padding-bottom: 20px;
  }
}
</style>
